package com.cqhilink.api.common.utils.security.base64;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * BASE64编码
 * Created by wangzhen on 2016/6/6.
 */
public class Base64Encod {
    /**
     * 将字节进行base64编码
     *
     * @param bytes
     * @return
     */
    public static String byte2base64(byte[] bytes) {
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(bytes);
    }

    /**
     * 将base64编码的字符串转换成字节
     *
     * @param base64
     * @return
     * @throws IOException
     */
    public static byte[] base642byte(String base64) throws IOException {
        BASE64Decoder base64Decoder = new BASE64Decoder();
        return base64Decoder.decodeBuffer(base64);
    }
}
